// Learn cc.Class:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/class/index.html
// Learn Attribute:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/reference/attributes/index.html
// Learn life-cycle callbacks:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/life-cycle-callbacks/index.html
var cow_skin = cc.Class({
    name: "cow_skin",
    properties: {
        skin_sprits: {
            type: cc.SpriteFrame,
            default: [],
        }
    },
});



cc.Class({
    extends: cc.Component,

    properties: {
        cow_skin: {
            default: [],
            type: cow_skin,
        },

    },

    // LIFE-CYCLE CALLBACKS:

    onLoad: function () {
        this.anim_cow = this.node.addComponent("Ani_frame");
        //随机创建对应的牛
        this.cow_type = Math.floor(Math.random() * 3 + 1);
        if (this.cow_type >= 4) {
            this.cow_type = 1;
        }
        this.game_Scene = cc.find("Canvas").getComponent("GameManage");
        this.cow_walk();
        this.moveSpeedX = Math.random() * 200 + 100;
    },
    cow_walk: function () {
        this.anim_cow.sprite_frames = this.cow_skin[this.cow_type - 1].skin_sprits;
        this.anim_cow.duration = 0.2;
        this.anim_cow.play_loop();
    },
    //start() {},
    update(dt) {
        this.node.x -= dt * this.moveSpeedX;
        if (this.node.x < -550) {
            this.game_Scene.removeFrom_CowArr();
            this.node.removeFromParent();
        }
    },
});
